//
// Created by castle on 2020/9/12.
//

#include "Game.h"


Game::Game()
{
	logic = new GameLogic();
	render = new GameRender("Tic Tac Toe", 600, 600);
}

Game::~Game()
{
	delete logic;
	delete render;
}

void Game::Run()
{
	bool runFlag = true;
	GameLogic::GameStatue result = GameLogic::GameStatue::Playing;
	while(runFlag)
	{
		auto cells = (uint8_t*)logic->GetCells();
		auto cellPicked = render->DrawCellsAndGetMouseEvent(cells);
		if(logic->GetPlayerNow() == 2)
		{
			cellPicked = Ai::PickNextCell(cells, false);
		}
		if(cellPicked >= 0 && result == GameLogic::GameStatue::Playing)
		{
			result = logic->PickCell(cellPicked);
		}
		render->DrawInfo(result, logic->GetPlayerNow());
		runFlag = render->Update();
	}
}
